<template>
  <div>
    <div style="float:left;padding:15px;">联系方式:</div>
    <el-card class="box-card" style="float:left;margin-top:15px;">
      <div class="text item">{{'地址 :' + formData.address }}</div>
      <div class="text item">{{'邮箱 :' + formData.email }}</div>
      <div class="text item">{{'电话 :' + formData.telPhone }}</div>
      <div class="text item">{{'传真 :' + formData.fax }}</div>
    </el-card>
    <div style="float:left;padding:15px;">二维码：</div>
    <div style="float:left;padding-top:15px;">
      <img
        style="width:200px;height:300px;box-shadow:0 2px 12px 0 rgba(0,0,0,.1);"
        :src="formData.img"
      />
    </div>
    <el-button @click="dialogVisible = true" type="primary" class="btnRight">编辑</el-button>
    <!--弹框-->
    <el-dialog title="提示" :visible.sync="dialogVisible" width="50%" :before-close="handleClose">
      <div style="padding:15px;">联系方式:</div>
      <el-card class="box-card">
        <el-form label-width="70px">
          <el-form-item label="地址">
            <el-input v-model="formData.address"></el-input>
          </el-form-item>
          <el-form-item label="邮箱">
            <el-input v-model="formData.email"></el-input>
          </el-form-item>
          <el-form-item label="电话">
            <el-input v-model="formData.telPhone"></el-input>
          </el-form-item>
          <el-form-item label="传真">
            <el-input v-model="formData.fax"></el-input>
          </el-form-item>
        </el-form>
      </el-card>
      <div style="padding:15px;">二维码：</div>
      <div>
        <img
          style="width:200px;height:300px;box-shadow:0 2px 12px 0 rgba(0,0,0,.1);"
          :src="formData.img"
        />
        <label for="upload" class="ui-upload">upload</label>
        <input accept="image/*" ref="file" @change="previewPhoto" type="file" id="upload" style="display: none;" />
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitBtn">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { reqContact,reqContactEdit ,reqFeedback} from "../../api";
export default {
  data() {
    return {
      dialogVisible: false,
      formData: {
        email: "",
        telPhone: "",
        fax: "",
        address: "",
        img: require("../../assets/noPhoto.jpg")
      }
    };
  },
  created(){
    reqContact({}).then(res=>{
      this.formData=res[0]
    }).catch(err=>{
      console.log(err)
    })
  },
  methods: {
    previewPhoto() {
      var file = this.$refs.file.files[0];
      var fileReader = new FileReader();
      fileReader.readAsDataURL(file);
      fileReader.onload = () => {
        this.formData.img = fileReader.result;
      };
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then(_ => {
          done();
        })
        .catch(_ => {});
    },
    submitBtn(){
       this.dialogVisible = false;
      reqContactEdit(this.formData).then(res=>{
        this.$message({
          message:'编辑成功',
          type:'success'
        })
      }).catch(err=>{
        console.log(err);
        this.$message({
          message:'编辑失败'
        })
      })
    },
  }
};
</script>

<style scoped>
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-card {
  width: 480px;
}
.btnRight {
  float: right;
  margin: 15px 15px 0 0;
}
.ui-upload {
  height: 30px;
  width: 80px;
  background-color: #00abff;
  font-size: 14px;
  line-height: 30px;
  cursor: pointer;
  display: inline-block;
  text-align: center;
  color: #fff;
  border-radius: 3px;
  margin-left: 20px;
  position: relative;
  bottom: 10px;
}
</style>